package com.situ.vivamarket.intcp;

import com.situ.vivamarket.model.Admin;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.servlet.HandlerInterceptor;

public class AdminLoginInterceptor implements HandlerInterceptor {
    public static final String ADMIN_LOGIN = "@#current_admin_login";

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        Admin admin = (Admin) session.getAttribute(ADMIN_LOGIN);
        if (admin == null) { //没登录，不通过
            response.sendRedirect(request.getContextPath() + "/vm/sys/login");//跳转到登录页
            return false;
        }else{
            return true;
        }
    }
}
